package com.gugee.common.web.system.promise.validate;

import com.gugee.common.web.system.product.model.ReportRecord;
import com.gugee.common.web.system.product.repository.ReportRecordRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Optional;

/**
 * 解锁报告权限
 */
@Component
public class ReportLimit extends Validate {


    @Autowired
    ReportRecordRepository reportRecordRepository;

    @Override
    public Boolean validate(long roleId, Object... params) {
        Optional<ReportRecord> reportRecordOptional = reportRecordRepository.findByUserIdAndUidAndExpireTimeGreaterThan(Long.parseLong(params[0].toString()), Long.parseLong(params[1].toString()), new Date().getTime()/1000);

        if(reportRecordOptional.isPresent()){
            return true;
        }
        super.tips = "Please unlock";
        return false;
    }
}
